// 1998 >> North America - North Central NA, UVa699 The Falling Leaves
// 陈锋
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define _for(i, a, b) for (int i = (a); i < (b); ++i)

map<int, int> sums;
void readTree(int pos) {
  int u; scanf("%d", &u);
  if (u == -1) return;
  sums[pos] += u, readTree(pos - 1), readTree(pos + 1);
}

int main() {
  for (int t = 1; true; t++) {
    sums.clear(), readTree(0);
    if (sums.empty()) break;
    printf("Case %d:\n", t);
    for (map<int, int>::iterator it = sums.begin(); it != sums.end(); it++) {
      if (it != sums.begin()) printf(" ");
      printf("%d", it->second);
    }
    puts("\n");
  }
  return 0;
}
/*
算法分析请参考: 《入门经典-第2版》例题6-10
注意本题直接利用了输入的递归性质进行直接处理，无需构建内存中对应的树结构
*/
// 2625667 699 The Falling Leaves  Accepted  C++11 0.039 2020-01-25 14:36:44